import * as TYPES from "../../Action/xhqbBank/bank.jsx";

const initData = {
	supportedBankList: [],
	selectedBankList: undefined,
	selectedBankCard: {}
};

const bankReducer = (state = initData, { type, data }) => {
	switch (type) {
		case TYPES.SET_SELECTED_BANK_CARD:
			return {
				...state,
				selectedBankCard: state.selectedBankList.filter(
					item => item.cardNo === data
				)[0]
			};
		case TYPES.ADD_NEW_BANK:
			return {
				...state,
				selectedBankList: state.selectedBankList.concat(data),
				selectedBankCard: data
			};
		case TYPES.SET_SUPPORTED_BANK_LIST:
			return {
				...state,
				supportedBankList: data
			};
		case TYPES.SET_SELECTED_BANK_LIST:
			return {
				...state,
				selectedBankList: data
			};
		default:
			return state;
	}
};

export default bankReducer;
